package 历年真题;

import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by lenovo on 2017/3/26.
 */
public class q27 {

    public static int[] num = new int[100];
    public static int[][] result = new int[100][100];
    public static int[] temp = new int[100];
    public static boolean[] used = new boolean[100];
    public static int p, s;

    /**
     * 初始化
     */
    private static void init() {
        p = 0;
        s = 0;
        for (int i = 0; i < 100; i++) {
            num[i] = 10000;
            for (int j = 0; j < 100; j++) {
                result[i][j] = 10000;
            }
        }

        for(int i=0;i<used.length;i++){
            used[i] = false;
        }

    }

    /**
     * 输出搜索结果
     */
    private static void showResult(){
        for(int i=0;i<p;i++){
            for(int j=0;result[i][j]!=10000;j++){
                System.out.print(result[i][j]+" ");
            }
            System.out.println("");
        }
    }

    /**
     * 比较是否有重复的出现
     * @param len
     * @return
     */
    private static boolean cmp(int len){
        int i,j;
       for(i=0;i<p;i++){
           for(j=0;j<len;j++){
               if(result[i][j]!=temp[j])
                   break;
           }
           if(j==len){
               return false;
           }
       }
       return true;
    }

    /**
     * 存储可能的结果
     * @param n
     */
    private static void save(int n){
        int i,j,len;
        s=0;
        for(i=0;i<n;i++){
            if(used[i]==false){
                temp[s++] = num[i];
            }
        }

        len = s;
        s = 0;
        if(cmp(len)){
            for(i=0;i<len;i++){
                result[p][i] = temp[i];
            }
            p++;
        }
    }

    /**
     * 使用深度搜索进行搜索
     * @param sum
     * @param n
     * @param w_sum
     */
    private static void search(int sum,int n,int w_sum){
        if(sum>w_sum){
            return;
        }

        if(sum==w_sum){
            save(n);
            return;
        }

        for(int i=0;i<n;i++){
            if(used[i] == false){
                used[i] = true;
                search(sum+num[i],n,w_sum);
                used[i] = false;
            }
        }
    }


    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        init();
        int w_sum = scanner.nextInt();
        scanner.nextLine();
        int n = scanner.nextInt();
        scanner.nextLine();


        for(int i=0;i<n;i++){
               num[i]= Integer.parseInt(scanner.nextLine());
        }

        Arrays.sort(num);
        search(0,n,w_sum);
        showResult();
    }
}
